home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
BBS
/
SECOND_SIGHT
/
GEnie Cleaner.cpt
/
GEnie Cleaner.p
next >
Wrap
Text File
|
1991-12-20
|
4KB
|
130 lines
program GEnieCleaner;
uses
TextUtils;
const
ENDLINE = chr(13);
SPACE = ' ';
TAB = chr(9);
DOCTYPE = 'ttxt';
{----------------------------------------------------------------- }
function EndStrip (theString: str255): str255;
begin
while (theString[length(theString)] in [SPACE, TAB, ENDLINE]) & (length(theString) > 1) do
theString := copy(theString, 1, pred(length(theString)));
EndStrip := theString
end;
{----------------------------------------------------------------- }
function BeginStrip (theString: str255): str255;
begin
while (theString[1] in [SPACE, TAB, ENDLINE]) & (length(theString) > 1) do
theString := copy(theString, 2, 255);
BeginStrip := theString
end;
{----------------------------------------------------------------- }
function TwoSpaceStrip (theString: str255): str255;
begin
while (pos(' ', theString) > 1) & (length(theString) > 1) do
theString := omit(theString, pos(' ', theString), 1);
TwoSpaceStrip := theString
end;
{----------------------------------------------------------------- }
procedure ProcessFile (fileName: str255; readRef, vRef: integer);
var
err: OSErr;
logLine: str255;
writeRef, counter: integer;
FirstLine: boolean;
begin
Err := FSDelete(fileName, vRef);
Err := Create(fileName, vRef, DOCTYPE, 'TEXT');
if Err = NoErr then
begin
Err := FSOpen(fileName, vRef, writeRef);
while not AtEOF(readRef) & (Err = NoErr) do
begin
repeat
Err := ReadALine(readRef, logLine);
until ((pos('Number:', logLine) = 1) & (pos('Name: ', logLine) > 0)) | AtEOF(readRef) | (Err <> NoErr);
if (not AtEOF(readRef)) & (Err = NoErr) then
begin
logLine := copy(logLine, pos('Name:', logLine) + length('Name: '), 255);
Err := WrLn(writeRef, logLine);
for counter := 1 to 4 do {junk lines}
if (Err = NoErr) then
Err := ReadALine(readRef, logLine);
Err := WrLn(writeRef, '');
FirstLine := true;
repeat
Err := ReadALine(readRef, logLine);
if FirstLine then
logLine := BeginStrip(logLine);
logLine := EndStrip(logLine);
logLine := TwoSpaceStrip(logLine);
if (not (logLine[1] in [SPACE, ';', '.', TAB])) & (not FirstLine) & (pos('Keywords:', logLine) <> 1) then
logLine := concat(SPACE, logLine);
if pos('Keywords:', logLine) <> 1 then
Err := Wr(writeRef, logLine)
else
Err := WrLn(writeRef, concat(ENDLINE, ENDLINE, logLine, ENDLINE));
FirstLine := false;
until (pos('Keywords:', logLine) = 1) | AtEOF(readRef) | (Err <> NoErr)
end { if (not AtEOF(readRef)) & (Err = NoErr) }
end; { while not AtEOF(readRef) & (Err = NoErr) }
Err := FSClose(writeRef)
end
end;
{----------------------------------------------------------------- }
var
err: OSErr;
where: point;
reply: SFReply;
typeList: SFTypeList;
keepLooping: boolean;
currentLog: str255;
readRef: integer;
begin
MaxApplZone;
InitCursor;
typeList[0] := 'TEXT';
keepLooping := true;
where.v := 20;
where.h := 20;
while keepLooping = true do
begin
SFGetFile(where, '', nil, 1, typeList, nil, reply);
if reply.good then
begin
currentLog := reply.fName;
Err := FSOpen(currentLog, reply.vRefNum, readRef);
if (Err = NoErr) then
begin
SFPutFile(where, 'Please name report', concat(currentLog, '.clean'), nil, reply);
if reply.good then
ProcessFile(reply.fName, readRef, reply.vRefNum)
else
keepLooping := false
end;
Err := FSClose(readRef)
end
else
keepLooping := false
end
end.